

// 发送get请求





function get(url, params, headers, dataType) {
    return new Promise((resolve, reject) => {
        let xhr = new XMLHttpRequest

        xhr.onreadystatechange = () => {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    let res = xhr.responseText
                    switch (dataType) {
                        case 'json':
                            res = JSON.parse(res)
                            break;
                        default:
                            break;
                    }
                    resolve(res)
                } else {
                    reject(xhr.status)
                }
            }
        }

        xhr.open('get', `${url}?${params}`)

        for (let key in headers) {
            xhr.setRequestHeader(key, headers[key])
        }

        xhr.send(null)
    })
}